﻿using System;

namespace Tools
{
    public class MakeBytes
    {
        /// <summary>
        /// 合并两个字节数组
        /// </summary>
        /// <param name="_A"></param>
        /// <param name="_B"></param>
        /// <returns></returns>
        public static byte[] AddBytes(byte[] _A, byte[] _B)
        {
            byte[] _bytes = new byte[_A.Length + _B.Length];
            Buffer.BlockCopy(_A, 0, _bytes, 0, _A.Length);
            Buffer.BlockCopy(_B, 0, _bytes, _A.Length, _B.Length);
            return _bytes;
        }
        /// <summary>
        /// 如果为IsLittleEndian则进行反转处理
        /// </summary>
        /// <param name="_bytes"></param>
        public static byte[] IsLittleEndianToReverse(byte[] _bytes)
        {
            byte[] newBytes = Tools.MakeBytes.CopyNewBytes(_bytes);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(newBytes);
            return newBytes;
        }

        /// <summary>
        /// 拷贝一个字节数据副本
        /// </summary>
        /// <param name="_bytes"></param>
        /// <returns></returns>
        public static byte[] CopyNewBytes(byte[] _bytes)
        {
            byte[] b = new byte[_bytes.Length];
            Buffer.BlockCopy(_bytes, 0, b, 0, _bytes.Length);
            return b;
        }

        /// <summary>
        /// 接取数据
        /// </summary>
        /// <param name="_input"></param>
        /// <param name="startNum">0为第一个</param>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static byte[] CopyNewBytes(byte[] _input, int startNum, int length)
        {
            byte[] _bytes = new byte[length];
            //Array.Copy(_input, startNum, _bytes, 0, length);
            Buffer.BlockCopy(_input, startNum, _bytes, 0, length);
            return _bytes;
        }

        public static byte[] CopyNewBytes(byte[] _input, int length)
        {
            byte[] _bytes = new byte[length];
            //Array.Copy(_input, 0, _bytes, 0, length);
            Buffer.BlockCopy(_input, 0, _bytes, 0, length);
            return _bytes;
        }
    }
}